package action

import (
	"workspace/websocket/src/global"

	"github.com/valyala/gorpc"
)

var RPCdispatcher *gorpc.Dispatcher

func StartRPC(dispatcher *Dispatcher) {
	addr := global.Config.Section("rpc").Key("addr").String()
	RPCdispatcher = gorpc.NewDispatcher()
	RPCdispatcher.AddFunc("broadcast", dispatcher.Broadcast)
	rpcServer := gorpc.NewTCPServer(addr, RPCdispatcher.NewHandlerFunc())
	err := rpcServer.Start()
	if err != nil {
		global.Logger.Error(err.Error())
		return
	}
	defer rpcServer.Stop()
	select {}
}
